﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using GalaSoft.MvvmLight;

namespace chatGUI.Model
{
    public class friendListModel : ObservableObject
    {
        private string id;
        public string Id
        {
            get { return id; }
            set { Set(ref id, value); }
        }
        public string UserId
        {
            get => "User" + id.Substring(1);
        }
        private bool isGroup;
        public bool IsGroup
        {
            get => isGroup;
            set => Set(ref isGroup, value);
        }
        private string avatarUrl;
        public string AvatarUrl
        {
            get { return avatarUrl; }
            set { avatarUrl = value; RaisePropertyChanged(() => AvatarUrl); }
        }
        private string friendNickName;
        public string FriendNickName
        {
            get { return friendNickName; }
            set { friendNickName = value; RaisePropertyChanged(() => FriendNickName); }
        }
        private string lastChatContent;
        public string LastChatContent
        {
            get { return lastChatContent; }
            set { lastChatContent = value; RaisePropertyChanged(() => LastChatContent); }
        }
        private DateTime lastChatTime;
        public DateTime LastChatTime
        {
            get { return lastChatTime; }
            set { lastChatTime = value; RaisePropertyChanged(() => LastChatTime); }
        }
        public string LastChatTimeStr
        {
            get { return judgeTime(LastChatTime); }
        }
        private int unreadChatNum;
        public int UnreadChatNum {
            get { return unreadChatNum; }
            set { unreadChatNum = value; RaisePropertyChanged(() => UnreadChatNum); Visibility = unreadChatNum == 0 ? false : true; }
        }
        private bool visibility;
        public bool Visibility
        {
            get => visibility;
            set => Set(ref visibility, value);
        }
        private static string judgeTime(DateTime dateTime)
        {
            if (dateTime < DateTime.Now.AddDays(-2))
            {
                return dateTime.ToString("MM-dd");
            }
            if(dateTime < DateTime.Now.AddDays(-1))
            {
                return "yestarday";
            }
            return dateTime.ToString("HH:mm");
        }
    }
}
